<?php
function reequipment_adminapi_updateorder($args)
{
    // Get arguments from argument array
    extract($args);

    /* Fields
    order_id,
	part_number,
	description	,
	model_id,
	equipment_id, 	 	
	company_id, 	 	
	last_ordered, 	 	
	date_expected,
	man_part_number,	 
	cost,
	agent,
	tracking_number,
	return_auth,	 	 
	credit_memo,	 
	date_returned
	*/
	
	$date_returned = strtotime($date_returned);
	$date_expected = strtotime($date_expected);

    // Get datbase setup
    $dbconn =& xarDBGetConn();
    $xartable =& xarDBGetTables();
    $table = $xartable['reordered'];
    $update = array();
    $bindvars = array();

    // Update item
    $query = "UPDATE $table SET ";
    if (isset($order_id)){
        $update[] = "order_id = ? ";
        $bindvars[] = $order_id;
    }
    if (isset($part_number)){
        $update[] = "part_number = ? ";
        $bindvars[] = $part_number;
    }
    if (isset($description)){
        $update[] = "description = ? ";
        $bindvars[] = $description;
    }
    if (isset($model_id)){
        $update[] = "model_id = ? ";
        $bindvars[] = $model_id;
    }
    if (isset($equipment_id)){
        $update[] = "equipment_id = ? ";
        $bindvars[] = $equipment_id;
    }
    if (isset($company_id)){
        $update[] = "company_id = ? ";
        $bindvars[] = $company_id;
    }
    if (isset($last_ordered)){
        $update[] = "last_ordered = ? ";
        $bindvars[] = $last_ordered;
    }
    if (isset($date_expected)){
        $update[] = "date_expected = ? ";
        $bindvars[] = $date_expected;
    }
    if (isset($man_part_number)){
        $update[] = "man_part_number = ? ";
        $bindvars[] = $man_part_number;
    } 
    if (isset($cost)){
        $update[] = "cost = ? ";
        $bindvars[] = $cost;
    }        
    if (isset($agent)){
        $update[] = "agent = ? ";
        $bindvars[] = $agent;
    }
    if (isset($tracking_number)){
        $update[] = "tracking_number = ? ";
        $bindvars[] = $tracking_number;
    }
    if (isset($return_auth)){
        $update[] = "return_auth = ? ";
        $bindvars[] = $return_auth;
    }
    if (isset($credit_memo)){
        $update[] = "credit_memo = ? ";
        $bindvars[] = $credit_memo;
    }
    if (isset($date_returned)){
        $update[] = "date_returned = ? ";
        $bindvars[] = $date_returned;
    }
    $query .= join(",",$update);
    $query .= "WHERE order_id = ? ";
    $bindvars[] = $order_id;
    $result =& $dbconn->Execute($query, $bindvars);
    if (!$result) return;
    // Let any hooks know that we have created a new topic
    $args['module'] = 'reequipment';
    $args['itemtype'] = 7; //tag
    $args['itemid'] = $order_id;
    xarModCallHooks('item', 'update', $order_id, $args);
    
    // Return the id of the newly created link to the calling process
    return true;
}
?>